#!/bin/bash

source ./config.sh

APP_t=$1
APP_t2=${APP_t##*/}
ENERGY=$2
INPUT_SAMPLE=$3
INPUT_BFIELD=$4
INPUT_PYLIST=$5
THREAD=$6

INPUT_FILE_NAME=${INPUT_FILE_DIR}/${APP_t2}_${ENERGY}GeV_${INPUT_SAMPLE}_${INPUT_BFIELD}.in

OUTPUT_FILE_NAME=${OUTPUT_FILE_DIR}/${APP_t2}_${ENERGY}GeV_${INPUT_SAMPLE}_${INPUT_BFIELD}Tesla_${INPUT_PYLIST}_${THREAD}_'$1'.out

ERROR_FILE_NAME=${OUTPUT_FILE_DIR}/${APP_t2}_${ENERGY}GeV_${INPUT_SAMPLE}_${INPUT_BFIELD}Tesla_${INPUT_PYLIST}_${THREAD}_'$1'.err

JOB_FILE_NAME=${JOB_FILE_DIR}/${APP_t2}_${ENERGY}GeV_${INPUT_SAMPLE}_${INPUT_BFIELD}Tesla_${INPUT_PYLIST}_${THREAD}.sh


case $INPUT_PYLIST in
  FTFP )
    pl=FTFP_BERT
    ;;  
  QGSP )
    pl=QGSP_BERT
    ;;  
  BIC )
    pl=QGSP_BIC
    ;;  
  LHEP )
    pl=LHEP
    ;;  
esac

cat > ${JOB_FILE_NAME} <<EOF
#!/bin/bash 
#$ -V
#$ -cwd
#$ -pe openmp $THREAD
#$ -q small
export PHYSLIST=$pl
$APP_t ${INPUT_FILE_NAME} ${THREAD} > ${OUTPUT_FILE_NAME} 
EOF

chmod +x ${JOB_FILE_NAME}
